package org.begincode.course.service;


import com.begincode.common.constant.Constant;
import org.begincode.core.mapper.*;
import org.begincode.core.model.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yangsj on 2016/4/30.
 */
@Service
public class CourseService {
    @Resource
    private BizCourseMapper bizCourseMapper;
    @Resource
    private CourseTypeMapper courseTypeMapper;
    @Resource
    private CourseLabelMapper courseLabelMapper;
    @Resource
    private CourseLevelMapper courseLevelMapper;

    /**
     * id查询course
     * */
    public Course selectCourseById(Integer courseId){
        return bizCourseMapper.selectByPrimaryKey(courseId);
    }
    /**
     * 查询课程列表
     * */
    public List<Course> selectCourses(){
        CourseExample courseExample = new CourseExample();
        courseExample.createCriteria().andDeleteFlagEqualTo(Constant.NO_DEL_FLAG);
        return bizCourseMapper.selectByExample(courseExample);
    }

    /**
     * 查询全部标签
     * */
    public List<CourseLabel> selectLabels(){
        CourseLabelExample courseLabelExample = new CourseLabelExample();
        courseLabelExample.createCriteria().andDeleteFlagEqualTo(Constant.NO_DEL_FLAG);
        return courseLabelMapper.selectByExample(courseLabelExample);
    }

    /**
     * 查询全部教程类型
     * */
    public List<CourseType> selectCourseTypes(){
        CourseTypeExample courseTypeExample = new CourseTypeExample();
        courseTypeExample.createCriteria().andDeleteFlagEqualTo(Constant.NO_DEL_FLAG);
        return courseTypeMapper.selectByExample(courseTypeExample);
    }

    /**
     * 查询级别
     * */
    public List<CourseLevel> selectCourseLevels(){
        CourseLevelExample courseLevelExample = new CourseLevelExample();
        courseLevelExample.createCriteria().andDeleteFlagEqualTo(Constant.NO_DEL_FLAG);
        return courseLevelMapper.selectByExample(courseLevelExample);
    }

    public void batchUpdateAddCountById(List<Course> list){
        bizCourseMapper.batchUpdateAddCountById(list);
    }
}
